home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 25
/
CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso
/
CUCD
/
WWW
/
http
/
www.cu-amiga.co.uk
/
features
/
c-tutorial
/
Part-2.lzx
/
Part-2
/
mouse1.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-09-10
|
2KB
|
93 lines
#include<exec/libraries.h>
#include<intuition/intuition.h>
#include<utility/tagitem.h>
#include<graphics/text.h>
#include<string.h>
#include<clib/exec_protos.h>
#include<clib/graphics_protos.h>
#include<clib/intuition_protos.h>
struct Library* GfxBase;
struct Library* IntuitionBase;
/* Need to give a prototype for our message handling function */
void handleIDCMP(struct Window*);
void main()
{
/* Open libraries... */
if(GfxBase = OpenLibrary("graphics.library",36))
{
if(IntuitionBase = OpenLibrary("intuition.library",36))
{
/* Open our window */
struct Window* win;
if(win = OpenWindowTags(NULL,
WA_Left, 20,
WA_Top, 20,
WA_Width, 200,
WA_Height, 100,
WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_REPORTMOUSE,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE,
TAG_DONE, 0))
{
/* If window opened, handle its IDCMP messages */
handleIDCMP(win);
CloseWindow(win);
}
CloseLibrary(IntuitionBase);
}
CloseLibrary(GfxBase);
}
}
/* Our message handling code */
void handleIDCMP(struct Window* win)
{
char* text = "Hello World!";
int going = TRUE;
int drawing = FALSE;
SetAPen(win->RPort, 1);
/* Loop, waiting for messages, until the close gadget clicked */
while(going)
{
struct IntuiMessage* intuimsg;
/* Wait for messages to arrive */
WaitPort(win->UserPort);
/* Messages have arrived: loop through all of them */
while(intuimsg = (struct IntuiMessage*)GetMsg(win->UserPort))
{
/* Act on this message... */
switch(intuimsg->Class)
{
case IDCMP_MOUSEBUTTONS:
switch(intuimsg->Code)
{
case SELECTDOWN:
drawing = TRUE;
break;
case SELECTUP:
drawing = FALSE;
break;
}
/* Omit the break to draw on click, too */
break;
case IDCMP_MOUSEMOVE:
if(drawing)
{
Move(win->RPort, intuimsg->MouseX, intuimsg->MouseY);
Text(win->RPort, text, strlen(text));
}
break;
case IDCMP_CLOSEWINDOW:
going = FALSE;
break;
}
/* Reply when finished with message */
ReplyMsg((struct Message*)intuimsg);
}
}
}